﻿using System;
using System.Web;
using System.Web.UI;
using MyHealthByDesign.Helper;

namespace MyHealthByDesign
{
    public partial class _Default : System.Web.UI.Page
    {
        Domain.Domain domain = new Domain.Domain();

        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            string email = txtEmail.Text;
            string password = txtPassword.Text;

            if (domain.IsValidUser(email, password))
            {
                Response.Redirect("Views/MyHealth.aspx");
            }

            DisplayErrorMessage("Invalid email or password. Please try again!");
        }

        public static void DisplayErrorMessage(string message)
        {
            var currentPage = HttpContext.Current.Handler as Page;
            if (currentPage != null) currentPage.Validators.Add(new ValidationError(message));
        }
    }
}